<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增作业管理')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-homework-add">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">作业标题：</label>
            <div class="col-sm-8">
                <input name="homeworkTopic"  class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">作业内容：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" name="homeworkContent">
                <div class="summernote" id="homeworkContent"></div>
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label is-required">分值：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input name="homeworkScore" class="form-control" type="number" required>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">作业类型：</label>
            <div class="col-sm-8">
                <select name="homeworkType" class="form-control m-b"
                        th:with="type=${@dict.getType('cws_homework_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">课程：</label>
            <div class="col-sm-8">
                <select class="form-control m-b" name="courseId" required>
                    <option value=""></option>
                    <option th:each="course : ${courses}" th:text="${course.courseName}"
                            th:value="${course.courseId}">
                    </option>
                </select>
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">开始时间：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <div class="input-group date">-->
<!--                    <input name="startTime" class="form-control" placeholder="yyyy-MM-dd" type="text">-->
<!--                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">截止时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="endTime" class="form-control" placeholder="" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">其他信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: summernote-js"/>
<script th:inline="javascript">
    function saveHomework() {
        $("#homeworkContent").removeClass("no-padding");
        var aHTML = $('.click2edit').summernote('code');
        $('.click2edit').summernote('destroy');
    }

    var prefix = ctx + "cws/homework"
    $("#form-homework-add").validate({
        focusCleanup: true
    });


    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-homework-add").serializeArray();
            $.operate.saveTab(prefix + "/add", data);
        }
    }

    $("input[name='startTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='endTime']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $(function () {
        $('.summernote').summernote({
            lang: 'zh-CN',
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });
</script>
</body>
</html>